<template>
	<view class="store-dividend-record">
		<view class="record-item" v-for="(item,index) in list" :key="index">
			<view class="date">
				{{item.divideDate}}
				<text v-if="item.lastMouthBalance<0">（{{getPreviousMonth(item.divideDate)}}月利润结余{{item.lastMouthBalance}}）</text>
			</view>
			<view class="details-info flexWrap">
				<view class="detail-item flexWarpCenterColumn">
					<text class="value">{{item.totalIncome||0}}</text>
					<text class="label">总收入</text>
				</view>
				<view class="detail-item flexWarpCenterColumn">
					<text class="value	special" @tap="goPage(`/micro-shareholder/selfShareholderCostManage?storeId=${storeId}`)">{{item.totalCost||0}}</text>
					<text class="label">总成本</text>
				</view>
				<view class="detail-item flexWarpCenterColumn">
					<text class="value">{{item.totalProfit||0}}</text>
					<text class="label">总利润</text>
				</view>
				<view class="detail-item flexWarpCenterColumn">
					<text class="value">{{item.totalDivide||0}}</text>
					<text class="label">应分总分红</text>
				</view>
				<view class="detail-item flexWarpCenterColumn">
					<text class="value">{{item.eachSharesDivide||0}}</text>
					<text class="label">每股应分红</text>
				</view>
				<view class="detail-item flexWarpCenterColumn">
					<text class="value">{{item.totalShares||0}}</text>
					<text class="label">应分总股数</text>
				</view>
			</view>
		</view>
		
		<uni-load-more v-if="showLoadStatus" :status="status" :size="14" :content-text="contentText" />
		<view class="quesheng" v-if="showEmpty">
			<image src="https://static.mo-yu.vip/wechat/images/orderEmpty.png"></image>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				storeId:'',
				list:[],
				page: 1,
				size: 10,
				showEmpty: true,
				showLoadStatus: false,
				more: true,
				contentText: {
					contentdown: '上拉加载更多~',
					contentrefresh: '加载中...',
					contentnomore: '已经到底了~~'
				},
				status: 'loading',
			}
		},
		onLoad(options) {
			this.storeId=options.storeId
			this.getList()
		},
		onPullDownRefresh() {
			this.freshList()
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 500)
		},
		onReachBottom() {
			if (this.more) {
				this.getList()
			}
		},
		methods:{
			freshList(){
				this.page = 1
				this.more = true
				this.status = 'loading'
				this.list = []
				this.getList();
			},
			
			// 获取分红数据
			getList(){	
				this.$request.post(this.$api.divideInfo, {
					storeId:this.storeId,
					pageNum:this.page++,  //当前页数
					pageSize:this.size,  //当前条数
					isMini:1,
				}, {
					isJava: true
				}).then(res => {
					if(res.code==200){
						let {
							data = {}
						} = res;
						let newArray = data.list
						
						if (newArray.length == 0 && this.page == 2) {
							this.showEmpty = true
							this.showLoadStatus = false
							this.more = false // 不能再次请求了
							return false;
						} else {
							this.showLoadStatus = true
							this.more = true
							this.showEmpty = false
							this.status = 'loading'
						}
						if (newArray.length < this.size) { // 说明没有更多数据
							this.status = 'noMore'
							this.more = false
							this.showEmpty = false
						}
						this.list = this.list.concat(newArray);
					}
				})
			},
			
			//  根据时间字符串获取上一月的月份
			getPreviousMonth(dateString) {
				const date = new Date(dateString);
				const currentMonth = date.getMonth() + 1;
				const previousMonth = new Date(date.getFullYear(), date.getMonth(), 0);
				return previousMonth.getMonth() + 1; // 上个月的月份
			},
		},
	}
</script>

<style lang="scss" scoped>
	.store-dividend-record{
		padding: 28rpx;
		.record-item{
			margin-bottom: 50rpx;
			.date{
				padding: 0 30rpx;
				font-size: 28rpx;
				color: #FD8926;
			}
			.details-info{
				margin-top: 10rpx;
				flex-wrap: wrap;
				gap: 20rpx 0;
				.detail-item{
					width: 33.3%;
					flex-shrink: 0;
					.value{
						color:rgba(255,255,255,1);
						font-size: 30rpx;
						font-weight: bold;
					}
					.label{
						margin-top: 4rpx;
						color:rgba(255,255,255,0.6);
						font-size: 26rpx;
					}
					.special{
						color:#26BCFD ;
					}
				}
			}
		}
	}
	.quesheng{
		margin-top: 200rpx;
		display: flex;
		justify-content: center;
		image{
			width: 476upx;
			height: 280upx;
		}
	}
</style>